Skip to content

BSL-40-AdminEventUI#38

Merged
rohanarcot merged 4 commits intomainfrom
bsl-40-admin-events-ui
Apr 17, 2026
Merged

BSL-40-AdminEventUI#38
rohanarcot merged 4 commits intomainfrom
bsl-40-admin-events-ui

Conversation

@sanjanamanivannan
Copy link
Copy Markdown
Contributor

Screenshot 2026-03-06 at 3 23 18 PM

Comment thread app/admin/events/page.tsx Outdated
const [startAt, setStartAt] = useState("");
const [location, setLocation] = useState("");

const [message, setMessage] = useState("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track success vs error...

const [message, setMessage] = useState<{ text: string; isError: boolean } | null>(null);

Now have to update every setMessage(...) call (I will create a comment on each one to help)

Comment thread app/admin/events/page.tsx Outdated

if (!res.ok) {
setEvents([]);
setMessage(data?.error || "Failed to load events");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: data?.error || "Failed to load events", isError: true });

Comment thread app/admin/events/page.tsx Outdated
setEvents(Array.isArray(data) ? data : []);
} catch {
setEvents([]);
setMessage("Failed to load events");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: "Failed to load events", isError: true });

Comment thread app/admin/events/page.tsx Outdated
return;
}

setMessage("Event created successfully");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: "Event created successfully", isError: false });

Comment thread app/admin/events/page.tsx Outdated
const data = await res.json();

if (!res.ok) {
setMessage(data?.error || "Failed to create event");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage({ text: data?.error || "Failed to create event", isError: true });

Comment thread app/admin/events/page.tsx Outdated

async function createEvent(e: React.FormEvent) {
e.preventDefault();
setMessage("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage(null);

Comment thread app/admin/events/page.tsx Outdated

async function loadEvents() {
setLoading(true);
setMessage("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setMessage(null);

Comment thread app/admin/events/page.tsx
}
}

return (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this for the role checking, adding to what i added above:

{canCreate && (
  <form onSubmit={createEvent} className="mt-6 space-y-4 max-w-md">
    ...
  </form>
)}
{!canCreate && (
  <p className="mt-6 text-sm text-gray-500">You do not have permission to create events.</p>
)}

Comment thread app/admin/events/page.tsx

import { useEffect, useState } from "react";
import AdminLayout from "@/components/admin/AdminLayout";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to incorporate RBAC (Role-based access control). So incorporate useSession() and hasRole()

here add this:

import { useSession } from "next-auth/react";
import { hasRole } from "@/lib/rbac";

Comment thread app/admin/events/page.tsx
};

export default function AdminEventsPage() {
const [events, setEvents] = useState<Event[]>([]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing with the RBAC comments, add this right under AdminEventsPage() and keep the other stuff:

  const { data: session } = useSession();
  const canCreate = hasRole(session?.user?.role ?? "USER", "AMBASSADOR");

@rohanarcot rohanarcot merged commit 7e2670a into main Apr 17, 2026
@rohanarcot rohanarcot deleted the bsl-40-admin-events-ui branch April 17, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants